<%@page pageEncoding="utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<form action="${pageContext.request.contextPath}/bookManage/borrowBook/borrow.do?method=borrow" method="post" onSubmit="return(checkborrow());">
<table width='100%' height="360" border='1' cellspacing='0' cellpadding='0'>
<tr>
	<td align="center" width="35%">
			<table height="360">
				<tr height="30">
					<td><span>借书证号：</span><input type="text" name="libcard"></td>
					<td><input type="button" onclick="javascript:getuser()" value="查询"></td>
				</tr>
				<tr height="330">
					<td colspan="2"><div id="reader"><span style="color: #FF9933">${borrowfail}</span></div></td>
				</tr>
			</table>
	</td>
	<td  align="center" width="65%">
		<table>
			<tr height="30">
				<td><span>图书编号：</span><input type="text" name="bookno"></td>
				<td><input type="button" onclick="javascript:getbook()" value="查询"></td>
			</tr>
			<tr height="330">
				<td colspan="2"><div id="book"><span style="color: #FF9933">${borrowfail}</span></div></td>
			</tr>
		</table>
	</td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="submit" value=" < 借阅图书 > "></td></tr>
</table>
</form>
<script type="text/javascript" src="${pageContext.request.contextPath}/common/js/ajax.js"></script>
	<script type="text/javascript">
	var client = null;
	var url = null;
	function getuser(){
		 var contents="?method="+'showoneuser';
		 client = createRequest();
		 url="${pageContext.request.contextPath}/bookManage/borrowBook/borrow.do";
		 var libcard = document.getElementById('libcard').value;
		 if(isNaN(libcard)){
		 	alert("借书证号必须为数字！");
		 	return false;
		 }
		 contents += "&libcard="+libcard;
		 contents = encodeURI(contents,"utf-8");
		 url+=contents;
		 		// alert(url);
		 client.open("post",url,true);
		 client.onreadystatechange = handleResult;
		 client.send(contents);
	}
	
	function handleResult(){
		if(client.readyState==4){
			var response = client.responseText;
			var div = document.getElementById("reader");
			//alert(response);
			div.innerHTML=response;
		}
	}
	function getbook(){
		 var contents="?method="+'showonebook';
		 client = createRequest();
		 url="${pageContext.request.contextPath}/bookManage/borrowBook/borrow.do";
		 var bookno = document.getElementById('bookno').value;
		 contents += "&bookno="+bookno;
		 contents = encodeURI(contents,"utf-8");
		 url+=contents;
		 		// alert(url);
		 client.open("post",url,true);
		 client.onreadystatechange = handleResultbook;
		 client.send(contents);
	}
	
	function handleResultbook(){
		if(client.readyState==4){
			var response = client.responseText;
			var div = document.getElementById("book");
			//alert(response);
			div.innerHTML=response;
		}
	}
	
	function checkborrow(){
		 var no = document.getElementById('bookName');
		 var lib_card = document.getElementById('lib_card');
		 if(lib_card==null){
		 	alert("借书证号不能为空！");
		 	return false;
		 }
		  if(no==null){
		 	alert("图书编号不能为空！");
		 	return false;
		 }
		return true;
	}
</script>